#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution 
// 
// Project : JackieHan.NHibernate3.Test
// 
// File : TestBagMapping.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : BagMappingTest
// 
// History : 
//			2010-09-16 00:03:42	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using JackieHan.NHibernate3.Domain;
using JackieHan.NHibernate3.Repository;
using NUnit.Framework;

#endregion

namespace JackieHan.NHibernate3.Test
{
    /// <summary> 
    /// BagMappingTest
    /// </summary>
    [TestFixture]
    public class TestBagMapping
    {
        [Test]
        public void TestBaseTypeBag()
        {
            BagOfElements item = new BagOfElements
                                     {
                                         CreateDate = DateTime.Now,
                                         Creator = "admin",
                                         Elements = new string[] {"aaa", "bbb", "ccc", "ddd"},
                                         LastUpdateDate = DateTime.Now,
                                         Updator = "admin",
                                         Version = 1
                                     };
            BagOfElementsRepository db = new BagOfElementsRepository();
            db.Save(item);
        }

        [Test]
        public void TestComponentBag()
        {
            BagOfComponents item = new BagOfComponents
                                       {
                                           Components = new List<ComponentBag>
                                                            {
                                                                new ComponentBag
                                                                    {IntProperty = 1, StringProperty = "aaa"},
                                                                new ComponentBag
                                                                    {IntProperty = 2, StringProperty = "bbb"},
                                                                new ComponentBag
                                                                    {IntProperty = 3, StringProperty = "ccc"}
                                                            },
                                           CreateDate = DateTime.Now,
                                           Creator = "admin",
                                           LastUpdateDate = DateTime.Now,
                                           Updator = "admin",
                                           Version = 1
                                       };
            BagOfComponentsRepository db = new BagOfComponentsRepository();
            db.Save(item);
        }

        [Test]
        public void TestComponentWithParentBag()
        {
            BagOfComponentsWithParent item = new BagOfComponentsWithParent
                                                 {
                                                     CreateDate = DateTime.Now,
                                                     Creator = "admin",
                                                     Updator = "admin",
                                                     LastUpdateDate = DateTime.Now
                                                 };
            item.Components = new List<ComponentsWithParentBag>
                                  {
                                      new ComponentsWithParentBag
                                          {IntProperty = 1, Parent = item, StringProperty = "aaa"},
                                      new ComponentsWithParentBag
                                          {IntProperty = 2, Parent = item, StringProperty = "bbb"},
                                      new ComponentsWithParentBag
                                          {IntProperty = 3, Parent = item, StringProperty = "ccc"},
                                      new ComponentsWithParentBag
                                          {IntProperty = 4, Parent = item, StringProperty = "ddd"}
                                  };

            BagOfComponentsWithParentRepository db = new BagOfComponentsWithParentRepository();
            db.Save(item);
        }

        [Test]
        public void TestNestedComponentsWithParentBag()
        {
            BagOfNestedComponentsWithParent item = new BagOfNestedComponentsWithParent
            {
                CreateDate = DateTime.Now,
                Creator = "admin",
                Updator = "admin",
                LastUpdateDate = DateTime.Now
            };
            NestedComponents nestedComponents1 = new NestedComponents
                                                     {IntProperty = 1, Parent = item};
            nestedComponents1.Nested = new NestedComponentsWithParent
                                           {Parent = nestedComponents1, StringProperty = "aaa"};
            NestedComponents nestedComponents2 = new NestedComponents
                                                     {IntProperty = 2, Parent = item};
            nestedComponents2.Nested = new NestedComponentsWithParent { Parent = nestedComponents2, StringProperty = "bbb" };
            NestedComponents nestedComponents3 = new NestedComponents
                                                     {IntProperty = 3, Parent = item};
            nestedComponents3.Nested = new NestedComponentsWithParent { Parent = nestedComponents3, StringProperty = "ccc" };
            NestedComponents nestedComponents4 = new NestedComponents
                                                     {IntProperty = 4, Parent = item};
            nestedComponents4.Nested = new NestedComponentsWithParent { Parent = nestedComponents4, StringProperty = "ddd" };
            item.Components = new List<NestedComponents>();
            item.Components.Add(nestedComponents1);
            item.Components.Add(nestedComponents2);
            item.Components.Add(nestedComponents3);
            item.Components.Add(nestedComponents4);
            BagOfNestedComponentsWithParentRepository db=new BagOfNestedComponentsWithParentRepository();
            db.Save(item);
        }

        [Test]
        public void TestOneToManyBag()
        {
            BagOfOneToMany item = new BagOfOneToMany
                                  {
                                      CreateDate = DateTime.Now,
                                      Creator = "admin",
                                      LastUpdateDate = DateTime.Now,
                                      Updator = "admin",
                                      Version = 1,
                                      OneToManys = new List<OneToManyBag>
                                                       {
                                                           new OneToManyBag(),
                                                           new OneToManyBag(),
                                                           new OneToManyBag(),
                                                           new OneToManyBag()
                                                       }
                                  };
            BagOfOneToManyRepository db = new BagOfOneToManyRepository();
            db.Save(item);
        }

        [Test]
        public void TestManyToManyBag()
        {
            BagOfManyToMany item1 = new BagOfManyToMany
                                       {
                                           CreateDate = DateTime.Now,
                                           Creator = "admin",
                                           LastUpdateDate = DateTime.Now,
                                           Updator = "admin",
                                           Version = 1,
                                           Name = "jackie"
                                     };
            BagOfManyToMany item2 = new BagOfManyToMany
            {
                CreateDate = DateTime.Now,
                Creator = "admin",
                LastUpdateDate = DateTime.Now,
                Updator = "admin",
                Version = 1,
                Name = "jackieHan"
            };

            ManyToManyBag child1 = new ManyToManyBag
                                       {
                                           Name = "child1",
                                           ManyToMany = new List<BagOfManyToMany> {item1, item2}
                                       };
            ManyToManyBag child2 = new ManyToManyBag
                                       {
                                           Name = "child2",
                                           ManyToMany = new List<BagOfManyToMany> {item1, item2}
                                       };
            item1.ManyToMany = new List<ManyToManyBag> {child1, child2};
            item2.ManyToMany = new List<ManyToManyBag> { child1, child2 };
            BagOfManyToManyRepository db = new BagOfManyToManyRepository();
            db.Save(new List<BagOfManyToMany> {item1, item2});
        }
    }
}